package com.clgk.wechatmall.role.dao.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Repository;

import com.clgk.wechatmall.common.ThreadLocals;
import com.clgk.wechatmall.common.sql.CommonDaoImpl;
import com.clgk.wechatmall.common.sql.Page;
import com.clgk.wechatmall.manager.entity.ManagerVo;
import com.clgk.wechatmall.role.bean.RoleBean;
import com.clgk.wechatmall.role.dao.RoleDao;

@Repository
public class RoleDaoImpl extends CommonDaoImpl implements RoleDao {

	@Override
	public Integer deleteByIds(String ids) {
		String sql = "DELETE FROM lampserver.T_ROLE WHERE ID IN ("+ids+")";
		return this.update(sql, new Object[]{});
	}

	@Override
	public List<RoleBean> queryList(RoleBean bean, Page page) {
		StringBuilder sql = new StringBuilder("");
		List<Object> params = new ArrayList<Object>();
		sql.append(" SELECT * ");
		sql.append(" FROM lampserver.T_ROLE t ");
		sql.append(" WHERE 1=1 ");
		ManagerVo backUser = ThreadLocals.getBackUser();
		if(backUser != null){
			sql.append(" AND FIND_IN_SET(t.`MANAGERID`,lampserver.`getManagerList`(?)) ");
			params.add(backUser.getId());
		}
		if(bean != null){
			if(bean.getId() != null){
				sql.append(" AND t.`ID`=? ");
				params.add(bean.getId());
			}
		}
		return this.query(sql.toString(), RoleBean.class, params, page);
	}

}
